Starting Mathematica


This is a basic introduction to Mathematica. Since Mathematica is a very powerful program
 with many features only a small fraction of its capabilities will be discussed here. See
 http://bartok.ucsc.edu/peter/115/math_intro/node1.html

or go to Mathematica\help. Unlike conventional computer languages Mathematica can do
 symbolic manipulation, has a huge number of built-in numerical functions, can do 
numerical calculations to arbitrary precision, and has powerful plotting routines which 
interface directly with the results of calculations. Mathematica can also be used for 
programming in styles which are quite different from those of C and fortran, but we will 
not discuss programming in Mathematica here. 

There are two interfaces to Mathematica: (i) a command line interface, and (ii) the
notebook interface. The same commands are given in both, but the notebook interface has 
some additional features.


If one starts Mathematica in Windows  by clicking on an icon one goes straight into the
notebook interface in which a separate window appears into which Mathematica commands are
 typed.  To execute a command in Windows, you need to hold down the Shift key as well as
 pressing Enter (just pressing Enter allows you to continue entering your command on the
 next line but does not execute it). 
 
A Simple Mathematica Session


Mathematica understands the usual operators + - * / and for exponentiation. It also
 
understands basic constants pi and E.  It also knows about a large number of mathematical 
 
functions such as Exp[x], Sin[x], Cos[x], ArcSin[x], Log[x]


The following session illustrates some of these features:
 
 
x = 7
[Graphics:math.txtgr2.gif][Graphics:math.txtgr1.gif]
 y = 19
[Graphics:math.txtgr2.gif][Graphics:math.txtgr3.gif]
x y
[Graphics:math.txtgr2.gif][Graphics:math.txtgr4.gif]
 (x + 3) y
[Graphics:math.txtgr2.gif][Graphics:math.txtgr5.gif]
 2^x
[Graphics:math.txtgr2.gif][Graphics:math.txtgr6.gif]
 Exp[ Pi]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr7.gif]
 

Two-Dimensional Plots



The basic plotting command is Plot[f, {x, xmin, xmax}]

which plots the function f(x) from xmin to xmax

For example,
 
 
[Graphics:math.txtgr2.gif][Graphics:math.txtgr8.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr9.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr10.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr11.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr12.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr13.gif]


The command Show can also be used to combine plots. Suppose we create plots of two functions using two separate

calls to Plot, e.g.

 

[Graphics:math.txtgr2.gif][Graphics:math.txtgr14.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr15.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr16.gif]
  
 
Integration
[Graphics:math.txtgr2.gif][Graphics:math.txtgr17.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr18.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr19.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr20.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr21.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr22.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr23.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr24.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr25.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr26.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr27.gif]


 
 
Defining Functions
 


There are many functions in Mathematica but it is often very useful to be able to define
 
functions oneself. This is illustrated by the following example, which defines the 
 
function . f(x) = x + x^2
 
 
 
[Graphics:math.txtgr2.gif][Graphics:math.txtgr28.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr29.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr30.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr31.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr32.gif]


Note two things about the first line:. First of all the underscore after the x, which is
 
called a ``blank'', stands for ``any expression'', so when the function is called, the 
 
argument can be named anything, not necessarily x. Secondly, the use of :=, rather than =,
 
 which means that the assignment is delayed until the function is called. In the present 
 
example it wouldn't have made any difference if we had used =, the normal assignment
 
 operator, but it would if the function depended on a parameter.  
 
 






 Series Expansions
.
Mathematica can work out series of complicated functions to very high order. The command
 
 is Series[f, {x, x0, n}] which expands f in powers of up to n-th order, e.g. to get the
 
 first 20 terms in the expansion of about x=0: 
 
 
[Graphics:math.txtgr2.gif][Graphics:math.txtgr33.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr34.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr35.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr36.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr37.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr38.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr39.gif]
[Graphics:math.txtgr2.gif][Graphics:math.txtgr40.gif]
  
 
Three-Dimensional Plots

We will learn how to plot cool surfaces like this one...

 

[Graphics:math.txtgr2.gif][Graphics:math.txtgr41.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr42.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr43.gif]

We will also learn how to plot curves in three dimensions.

 

[Graphics:math.txtgr2.gif][Graphics:math.txtgr44.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr45.gif]

[Graphics:math.txtgr2.gif][Graphics:math.txtgr46.gif]